package pattern1;

/**
 * 运算工厂
 *
 * @author wdl
 */
public class OperationFactory {
    /**
     * 根据输入的符号创建不同的对象
     * @param operate 输入运算符
     * @return 返回创建的对象
     */
    public static AbstractOperation createOperation(String operate) {
        AbstractOperation operation = null;
        switch (operate) {
            case "+":
                operation = new OperationAdd();
                break;
            case "-":
                operation = new OperationSub();
                break;
            case "*":
                operation = new OperationMul();
                break;
            case "/":
                operation = new OperationDiv();
                break;
            default:
        }
        return operation;
    }
}
